浙江SEO:教你多種方法實(shí)現(xiàn)301網(wǎng)頁重定向【代碼實(shí)例】
為什么需要使用301重定向:因?yàn)?01重定向能夠增加網(wǎng)站域名的權(quán)重,減少權(quán)重的流失,這樣有利于網(wǎng)站的SEO優(yōu)化以及排名
1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不會影響到搜索引擎對頁面的排名。
2. 保留訪客和流量: 如果你將頁面鏈接到大量方法可以訪問過的地址,如果不是用重定向的話你就會失去這些用戶(不解)原文:If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.
下面是 11 中實(shí)現(xiàn) 301 重定向的方法:
1. HTML 重定向/Meta 刷新
將下面 HTML 重定向代碼放在網(wǎng)頁的 <head> 節(jié)點(diǎn)內(nèi):
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com">
上述代碼立即將訪客重定向到另外一個頁面,你可以修改 content 中 的 0 這個值來表示幾秒鐘后才進(jìn)行重定向。例如 content="3; url=http://www.oschina.net/" 表示三秒后再重定向。
2. PHP 重定向
復(fù)制代碼 代碼如下:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
3. ASP Redirect
復(fù)制代碼 代碼如下:
< %@ Language=VBScript %>
< %
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%>
4. ASP .NET Redirect
復(fù)制代碼 代碼如下:
< script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
< /script>
5. JSP Redirect
復(fù)制代碼 代碼如下:
< %
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>
6. CGI PERL Redirect
復(fù)制代碼 代碼如下:
$q = new CGI;
print $q->redirect("http://www.new-url.com/");
7. Ruby on Rails Redirect
復(fù)制代碼 代碼如下:
def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end
8. ColdFusion Redirect
復(fù)制代碼 代碼如下:
< .cfheader statuscode="301" statustext="Moved permanently">
< .cfheader name="Location" value="http://www.new-url.com">
9. Javascript URL Redirect
復(fù)制代碼 代碼如下:
< head>
< script type="text/javascript">
window.location.href='http://www.newdomain.com/';
< /script>
< /head>
10. IIS Redirect
在 Internet 服務(wù)管理器中右擊你想要重定向的文件和文件夾,選擇 "a redirection to a URL".
然后輸入目標(biāo)網(wǎng)址,選中 "The exact url entered above" 和 "A permanent redirection for this resource" 然后點(diǎn)擊 'Apply' 按鈕。
11. 使用 .htaccess 進(jìn)行重定向
創(chuàng)建一個 .htaccess 文件(代碼如下)用來將訪問呢 domain.com 重定向到 www.domain.com 下,該文件必須放置在網(wǎng)站的root目錄,也就是首頁放置的目錄。
復(fù)制代碼 代碼如下:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
注意: .htaccess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模塊啟用的情況下使用。
12.Nginx中的rewrite
復(fù)制代碼 代碼如下:
server {
server_name 533999a.com seotz.net;
if ($host = 'seotz.net' ) {
rewrite ^/(.*)$ //533999a.com/$1 permanent;
}
總結(jié):頁面永久性移走(301重定向)是一種非常重要的“自動轉(zhuǎn)向”技術(shù)。網(wǎng)址重定向最為可行的一種辦法。當(dāng)用戶或搜索引擎向網(wǎng)站服務(wù)器發(fā)出瀏覽請求時(shí),服務(wù)器返回的HTTP數(shù)據(jù)流中頭信息(header)中的狀態(tài)碼的一種,表示本網(wǎng)頁永久性轉(zhuǎn)移到另一個地址。
「網(wǎng)站優(yōu)化」電話:13357671511
(備注:出于傳播知識、信息的目的,本站部分文章、圖片來源于網(wǎng)絡(luò),如有侵權(quán)請第一時(shí)間告知,小編核實(shí)后會立刻刪除,不接受、不回復(fù)任何形式的惡意索賠。)
- 提升用戶體驗(yàn)!百度搜索向權(quán)限問···
- 什么是https://?百度蜘···
- 「百度算法」藍(lán)天算法:背景、規(guī)···
- 「百度算法」颶風(fēng)算法:重塑互聯(lián)···
- 阿里旺旺網(wǎng)頁版登錄全攻略
- 百度驚雷算法深度解析與 SEO···
- 【原創(chuàng)】網(wǎng)站降權(quán)?別怕!原因排···
- 網(wǎng)站打開速度的測試與優(yōu)化秘籍
- 「百度優(yōu)化」如何讓搜索引擎認(rèn)可···
- 百度搜索引擎與外匯交易網(wǎng)站:屏···
- 百家號排名優(yōu)化介紹
- 即夢 AI 制作的小狗視頻
- 「亮劍被刪除后十集」《亮劍》原···
- 全面提升網(wǎng)站優(yōu)化效果的關(guān)鍵策略···
- 專業(yè) SEO 公司的關(guān)鍵詞與長···
- “百度信風(fēng)算法“:全面解析與深···
- 「百度指數(shù)」深度解析百度指數(shù):···
- “丈育” 是個什么鬼???“丈···
- “天網(wǎng)算法” 守護(hù)網(wǎng)絡(luò)安全,警···
- 「抖音SEO入門」用網(wǎng)站 SE···